set more off

*** read data ***

use "reassessments", clear

merge 1:1 swis_code year using "switchers"
drop _m

duplicates drop muni_name county_name year, force
merge 1:1 muni_name county_name year using "census demographics"
drop _m

merge 1:1 muni_name county_name year using "finances clean"
drop _m

merge 1:1 muni_name county_name year using "employment"
drop _m

merge 1:1 muni_name county_name year using "turnover"
keep if _m == 3

drop if mi(swis_code)
keep if year > 1986 & year < 2012

*** recode for interpretation ***

gen elected = 1-D
label variable elected "Elected assessor"
replace reass = reass * 100

keep if !mi(swis_code)
xtset swis_code year

#delimit;

local X1 
	lpopulation 
	lmedianincome 
	pct65plus 
	pctwhite 
	pctunemployed 
	pctrenter 
	pctagricuture
	;

#delimit cr

local X2 ltotalrevenue pctptax surpluspcp totalftequivalent

local X `X1' `X2'

foreach x in `X' {
	su `x'
	replace `x' = (`x' - r(min)) / (r(max) - r(min))
}


eststo clear

replace change = change * 100
eststo: areg change elected i.year, a(swis_code) cl(swis_code)
eststo: areg change elected i.year `X', a(swis_code) cl(swis_code)

replace change = change / 100
eststo: areg reass elected i.yea , a(swis_code) cl(swis_code)
eststo: areg reass elected i.yea `X', a(swis_code) cl(swis_code)

eststo: areg reass change i.year  , a(swis_code) cl(swis_code)
eststo: areg reass change i.year `X' , a(swis_code) cl(swis_code) 

#delimit;

esttab
	using "table A3a.tex"
	,
		replace
		cells(b(fmt(2) star) se(par))
		eqlabels(none)
		nomtitles
		collabels(none)
		gap
		keep(elected change)
		label
		mlabels(none)
		nonotes
		booktabs
		width(\hsize)
		indicate("Controls = lpopulation")
		stats(

			N
			,
				label(

					"Observations"
						
				)
				fmt(%20.0fc)
		)
		starlevels( + 0.10 * 0.05 ** 0.010 *** 0.001)
		mgroups(
				"DV = Assessor turnover" "DV = Reassessment", pattern(1 0 1 0 0 0 0 0)               
				prefix(\multicolumn{@span}{c}{) suffix(})   
				span erepeat(\cmidrule(lr){@span})
		)
		;
	
#delimit cr

eststo clear

eststo: areg reass change i.year if elected == 1, a(swis_code) cl(swis_code) 
eststo: areg reass change i.year `X' if elected == 1, a(swis_code) cl(swis_code) 

eststo: areg reass change i.year if elected == 0, a(swis_code) cl(swis_code) 
eststo: areg reass change i.year `X' if elected == 0, a(swis_code) cl(swis_code) 

#delimit;

esttab
	using "table A3b.tex"
	,
		replace
		cells(b(fmt(2) star) se(par))
		eqlabels(none)
		nomtitles
		collabels(none)
		gap
		keep(change)
		label
		mlabels(none)
		nonotes
		booktabs
		width(\hsize)
		indicate("Controls = lpopulation")
		stats(

			N
			,
				label(

					"Observations"
						
				)
				fmt(%20.0fc)
		)
		starlevels( + 0.10 * 0.05 ** 0.010 *** 0.001)
		mgroups(
				"Sample = Elected" "Sample = Appointed", pattern(1 0 1 0)               
				prefix(\multicolumn{@span}{c}{) suffix(})   
				span erepeat(\cmidrule(lr){@span})
		)
		;
	
#delimit cr
